package com.xm.xmds1705083.web.controller;

import com.xm.xm.dto.ResultDto;
import com.xm.xm.dto.SearchDto;
import com.xm.xmds1705083.service.service.DuoduoUserService;
import com.xm.xmds1705083.web.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 杭州新苗网络科技有限公司
 *
 * @author meihf
 * @create 2017/6/14
 * @description
 */
@Controller
@RequestMapping("/user")
public class UserController extends BaseController{

    @Autowired
    DuoduoUserService duoduoUserService;

    /**
     * 登录
     * @param searchDto
     * @return
     */
    @RequestMapping("/login")
    @ResponseBody
    public ResultDto login(@RequestBody SearchDto searchDto){
        return duoduoUserService.login(searchDto);
    }

    /**
     * 注册
     * @param searchDto
     * @return
     */
    @ResponseBody
    @RequestMapping("register")
    public ResultDto register(@RequestBody SearchDto searchDto){
        return duoduoUserService.register(searchDto);
    }

    /**
     * 忘记密码
     */
    @ResponseBody
    @RequestMapping("/updatePassword")
    public ResultDto updatePassword(@RequestBody SearchDto searchDto){
        return duoduoUserService.updatePassword(searchDto);
    }

    /**
     * 个人中心
     */
    @ResponseBody
    @RequestMapping("/myCenter")
    public ResultDto myCenter(@RequestBody SearchDto searchDto){
        searchDto.setAppUserId(getUserId());
        return duoduoUserService.myCenter(searchDto);
    }
    /**
     * 判断身份是否认证，通过身份证号，真实姓名，没有的话添加；
     */

    @ResponseBody
    @RequestMapping("/addMyselfCertf")
    public ResultDto addMyselfCertf(@RequestBody SearchDto searchDto){
       // searchDto.setAppUserId(getUserId());
        String authorization =   getRequest().getHeader("AUTHORIZATION");
        if (authorization!=null){
            searchDto.setAppUserId(Math.abs( Long.valueOf( authorization.split("\\_")[0] ) ));
        }
        return duoduoUserService.addMyselfCertf(searchDto);
    }




}
